package com.tony.ai.ui

import android.app.Instrumentation
import android.graphics.Bitmap
import android.os.Bundle
import android.util.Log
import androidx.camera.core.ImageProxy
import com.google.mlkit.common.model.LocalModel
import com.google.mlkit.vision.common.InputImage
import com.google.mlkit.vision.text.TextRecognition
import com.google.mlkit.vision.text.TextRecognizer
import com.google.mlkit.vision.text.chinese.ChineseTextRecognizerOptions
import com.google.mlkit.vision.text.latin.TextRecognizerOptions
import com.tony.ai.BaseActivity
import com.tony.ai.ai.TextRecognitionHelper
import com.tony.ai.camerax.CameraPreviewUtil
import com.tony.ai.databinding.ActivityTextRecognitionBinding

/**
 * 文本识别
 */
class TextRecognitionActivity : BaseActivity() {
    private val TAG = "TextRecognitionActivity"
    private lateinit var binding: ActivityTextRecognitionBinding
    private var textHelper: TextRecognitionHelper? = null
    override fun onGetBitmapResult(bitmap: Bitmap?, rotation: Int) {
        Log.e(TAG,"bitmapWidth=${bitmap?.width},bitmapHeight=${bitmap?.width}")
        textHelper?.startProcess(bitmap!!) { textResult ->
            binding.srcText.text = textResult
        }
    }

    override fun onImageProxyResult(image: ImageProxy) {
        super.onImageProxyResult(image)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityTextRecognitionBinding.inflate(layoutInflater)
        setContentView(binding.root)
        initViews()
    }

    private fun initViews() {
        textHelper = TextRecognitionHelper()
        initCameraX(CameraPreviewUtil.AnalyzerType.TEXT,binding.viewFinder)
    }
}